package com.naiterui.ehp.bs.patient.controller.inner;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.patient.exception.ExceptionCodes;
import com.naiterui.ehp.bs.patient.service.security.ISecurityService;
import com.naiterui.ehp.bs.patient.utils.exception.PatientBusinessException;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

/**
 * 登录校验Controller
 *
 * @author mudou
 * @since 2.8.0
 */
@Api(tags = {SwaggerTag.PATIENT + SwaggerTag.INNER_API + SwaggerTag.OTHER})
@Controller
@RequestMapping(value = "ap/inner/token")
public class ApInnerTokenController {

    @Autowired
    private ISecurityService securityService;

    /**
     * 校验Token
     * TokenController.checkToken()
     *
     * @param patientId
     * @param token
     *
     * @return
     *
     * @throws PatientBusinessException
     * @throws IOException
     * @Author mudou
     * @Date 2017年7月10日
     * @since 2.8.0
     */
    @ResponseBody
    @RequestMapping("check")
    public ResponseVO<Boolean> checkToken(Long patientId, String token) throws PatientBusinessException, IOException {

        if (null == patientId || StringUtils.isBlank(token)) {
            throw new PatientBusinessException(ExceptionCodes.PARAM_ERROR);
        }

        boolean result = this.securityService.saveCheckToken(patientId, token);

        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS, result);
    }
}
